
import 'package:app/utils/des/dart_des.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_jpf_core/widgets/down_timer_view.dart';
import 'package:flutter_jpf_core/widgets/widget_factory.dart';
import 'package:flutter_jpf_debug/flutter_jpf_debug.dart';
import 'dart:convert';

class UIPage extends StatefulWidget
{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return UIPageState();
  }

}

class UIPageState extends State<UIPage>
{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: WidgetFatory.createMyAppBar("UI", context),
      body:  Container(child: Column(
        children: [
          DownTimerView(controller,available: true,onTapCallback: (){
            //Future.delayed(Duration(milliseconds: 2000),(){
              controller.startCutDown();
              desDemo();
            //});
          },padding: EdgeInsets.all(10),margin: EdgeInsets.only(left: 60),)
        ],
      ),)
      ,);
  }

  DownTimerController controller = DownTimerController(totalSeconds: 10);

  void initData(){

  }

  void desDemo(){
    String key = '12345678'; // 8-byte
    String message = 'Driving in from the edge of town';
    List<int> encrypted;
    List<int> decrypted;
    List<int> iv = [1, 2, 3, 4, 5, 6, 7, 8];

    print('key: $key');
    print('message: $message');

    DES desECB = DES(key: key.codeUnits, mode: DESMode.ECB);
    encrypted = desECB.encrypt(message.codeUnits);
    decrypted = desECB.decrypt(encrypted);
    print('DES mode: ECB');
    print('encrypted: $encrypted');

    key = '123456781234567812345678'; // 24-byte
    DES3 des3CBC = DES3(key: key.codeUnits, mode: DESMode.CBC, iv: iv);
    encrypted = des3CBC.encrypt(message.codeUnits);
    decrypted = des3CBC.decrypt(encrypted);
    print('Triple DES mode: CBC');
    print('encrypted: $encrypted');
  }


}